var FillInfo = (function () {
    function FillInfo() {
        $("#btnRefreshStock").click(this, this.onbtnRefreshStockClick);
        $("#btnRefreshExRate").click(this, this.onRefreshExRateClick);

        this.onbtnRefreshStockClick({ data: this });
        this.onRefreshExRateClick({ data: this });
    }
    FillInfo.prototype.onbtnRefreshStockClick = function (eventArg) {
        eventArg.data.renderStockPrice();
    }
    FillInfo.prototype.onRefreshExRateClick = function (eventArg) {
        //防止过快请求
        $("#btnRefreshExRate").prop("disabled", true);
        setTimeout(function () { $("#btnRefreshExRate").prop("disabled",false); }, 3000);
        eventArg.data.renderExchangeRate();
    }
    FillInfo.prototype.renderStockPrice = function () {
        $.getJSON("/home/GetStockPrice", {}, function (data) {
            if (data != null && data.length > 0) {
                html = "";
                for (var s of data) {
                    let lineClass = "table-primary";
                    if (s.涨幅 > 0)
                        lineClass = "table-danger";
                    else if (s.涨幅 < 0)
                        lineClass = "table-success";
                    html += `<tr class=${lineClass}>
                    <td><a href="/home/ViewStockChart?code=${s.股票代码}">${s.股票名字}</a></td>
                    <td>${s.当前价格}</td>
                    <td>${s.涨幅.toFixed(2)}</td>
                    </tr>`
                }
                $("#stockTable tbody").html(html);
            }
        });
    }

    FillInfo.prototype.renderExchangeRate=function(){
        $.getJSON("/home/GetDollarExchangeRate", {}, function (data) {
            if (data != null && data.length > 0) {
                html = "";
                for (var s of data) {
                    html += `<tr> <td>${s.币种}</td>  <td>${s.汇买价}</td> <td>${s.钞买价}</td> <td>${s.汇卖价}</td> </tr>`
                }
                $("#exchangeRateTable tbody").html(html);
            }
        });
    }

    return FillInfo;
}());


var fillInfoObj = new FillInfo();